package com.osig.ec.cfca;

import cfca.paperless.client.servlet.PaperlessClient;
import cfca.paperless.client.util.StringUtil;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

// 获取合同模板  
public class GetTemplate {

	static String templateCode = "mb00";// 入参，模板号

	public static JSONArray  queryTemp(String codetemp)throws Exception {

		PaperlessClient clientAssistBean = new PaperlessClient(PaperlessConfig.assistUrl); // 无纸化辅助接口的访问URL
		String  operatorCode= "00001";
		// String tmpXml =
		// clientAssistBean.getTemplate(templateCode,"",operatorCode);//获取模板信息
		String tmpXml = clientAssistBean.getTemplate(codetemp, "", operatorCode);// 获取模板信息
		String code = StringUtil.getNodeText(tmpXml, "Code");// 成功为200，否则为错误码
		String message = StringUtil.getNodeText(tmpXml, "Message");// 错误信息
        JSONArray arr = new JSONArray();
		if (!"200".equals(code)) {
			System.out.println(code + ":" + message);
		} else {
			Object[] objArr = StringUtil.getXmlFieldArr(tmpXml, "Template");// 模板Xml文件数组
			for (Object obj : objArr) {
				String templateCode = StringUtil.getXmlField(obj.toString(), "TemplateCode");// 编号
				String templateName = StringUtil.getXmlField(obj.toString(), "TemplateName");// 名称
				System.out.println(templateCode + "---" + templateName);
				JSONObject jsonObj = new JSONObject();
				jsonObj.accumulate("templateCode", templateCode);
				jsonObj.accumulate("templateName", templateName);
				arr.add(jsonObj);
			}
		}
		return arr;
	}
	public static void main(String[] args) throws Exception {
		JSONArray queryTemp = queryTemp("0000000001");
		
		System.out.println(queryTemp.toString());
		String str= "{\"array\":[{\"contractid\":\"5838\",\"moduleid\":\"mb001\",\"contractname\":\"汽车业务模板\",\"contracttype\":\"初次购买\",\"firstparty\":\"兴展创\",\"secondparty\":\"\",\"thirdparty\":\"兴展创\"}]}";
        
         JSONObject  obj  = JSONObject.fromObject(str);
       // System.out.println(obj.get("array")); 
       //  System.out.println(obj.toString());
	
	}
}
